<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>抽奖页面</title>
    <style>
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            background-color: #f0f0f0;
            overflow: hidden; /* 防止内容滚动 */
        }
        #lottery-container {
            position: relative;
            width: 300px;
            height: 300px;
            text-align: center;
        }
        #gif {
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
            object-fit: cover;
        }
        #result-box {
            display: none;
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            padding: 20px;
            background-color: white;
            border-radius: 10px;
            box-shadow: 0 0 10px rgba(0,0,0,0.3);
            text-align: center;
            z-index: 999;
            width: 300px;
        }
    </style>
</head>
<body>
    <div id="lottery-container">
        <img id="gif" src="gifAndmp3/gamecity1.gif" alt="抽奖GIF">
        <div id="result-box"></div>
    </div>
    <script>
        const gif = document.getElementById('gif');
        const audio = new Audio('gifAndmp3/bgm.mp3');
        const resultBox = document.getElementById('result-box');

        function startLottery() {
            // 播放音频，如果不能自动播放，可以在用户交互后调用此函数
            audio.play().catch(error => console.log(error));

            setTimeout(() => {
                gif.style.display = 'none';
                resultBox.style.display = 'block';

                // 假设这里有实际的抽奖逻辑，如从数组中随机抽取一个奖品
                const prize = ['一等奖'];
                resultBox.innerText = `恭喜你获得${prize}！`;
            }, 19000);
        }

        // 如果需要在用户点击按钮后开始抽奖，请取消下面注释并添加按钮元素及事件监听器
        // const startBtn = document.createElement('button');
        // startBtn.textContent = '开始抽奖';
        // document.body.appendChild(startBtn);
        // startBtn.addEventListener('click', () => {
        //     startLottery();
        // });

        // 若允许自动播放，直接开始抽奖
        startLottery();
    </script>
</body>
</html>

